// run: $exec < input
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <unordered_set>
#include <vector>

int const maxn = 10007;
int father[maxn], area[maxn], tot[maxn], count[maxn], min[maxn];
int n;

int get_father(int x)
{
	return (x == father[x] ? x : (father[x] = get_father(father[x])));
}

void print(int id)
{
	std::string s = std::to_string(id);
	if (s.size() < 4) s = std::string(4 - s.size(), '0') + s;
	std::cout << s;
}

void set_union(int u, int v)
{
	int tu = get_father(u);
	int tv = get_father(v);
	if (tu != tv) {
		father[tv] = tu;
		area[tu] += area[tv];
		tot[tu] += tot[tv];
		count[tu] += count[tv];
		min[tu] = std::min(min[tu], min[tv]);
	}
}

struct data
{
	int id, count;
	double avtot, avarea;
};

int main()
{
	std::ios::sync_with_stdio(false);
	for (int i = 0; i < maxn; i++) { father[i] = min[i] = i; count[i] = 1; }
	std::cin >> n;
	std::unordered_set<int> all;
	for (int i = 0, id, dad, mum, k, ttot, tarea; i < n; i++) {
		std::cin >> id >> dad >> mum >> k;
		all.insert(id);
		std::vector<int> child(k);
		for (int j = 0; j < k; j++) {
			std::cin >> child[j];
			all.insert(child[j]);
		}
		std::cin >> ttot >> tarea;
		if (dad != -1) { set_union(id, dad); all.insert(dad); }
		if (mum != -1) { set_union(id, mum); all.insert(mum); }
		area[get_father(id)] += tarea;
		tot[get_father(id)] += ttot;
		for (int j = 0; j < k; j++) set_union(id, child[j]);
	}

	std::unordered_set<int> vis;
	std::vector<data> ans;
	for (auto i : all) {
		int t = get_father(i);
		if (vis.find(t) != vis.end()) continue;
		vis.insert(t);
		data tmp;
		tmp.id = min[t];
		tmp.count = count[t];
		tmp.avtot = tot[t] / (double)count[t];
		tmp.avarea = area[t] / (double) count[t];
		ans.push_back(tmp);
	}
	std::sort(ans.begin(), ans.end(), [](data const & a, data const & b) {
				return a.avarea > b.avarea || (a.avarea == b.avarea && a.id < b.id);
			});

	std::cout << ans.size() << '\n';
	for (auto i : ans) {
		print(i.id);
		std::cout << ' ' << i.count << ' ' << std::fixed << std::setprecision(3)
			<< i.avtot << ' ' << i.avarea << '\n';
	}
}

